namespace SinaFinance.SummaryInfoLibrary
{
    using System;
    using System.Diagnostics;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Browser;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Xml.Linq;

    public partial class StockProfessionInformationItem : UserControl
    {
        //private bool _contentLoaded;
        private XDocument doc;
        private string itemContent = string.Empty;
        //internal Grid LayoutRoot;
        private string newsHref = string.Empty;
        //internal Storyboard newsStoryboard;
        //internal Storyboard newsStoryboard_Copy1;
        //internal Path path;
        //internal TextBlock tbl;

        public StockProfessionInformationItem()
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.StockProfessionInformationItem_Loaded);
            this.tbl.MouseLeftButtonDown += new MouseButtonEventHandler(this.tbl_MouseLeftButtonDown);
            this.tbl.MouseEnter += new MouseEventHandler(this.tbl_MouseEnter);
            this.tbl.MouseLeave += new MouseEventHandler(this.tbl_MouseLeave);
            this.doc = XDocument.Load("PageConfig.xml");
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/SummaryInfoLibrary/StockProfessionInformationItem.xaml", UriKind.Relative));
        //        this.newsStoryboard = (Storyboard) base.FindName("newsStoryboard");
        //        this.newsStoryboard_Copy1 = (Storyboard) base.FindName("newsStoryboard_Copy1");
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.tbl = (TextBlock) base.FindName("tbl");
        //        this.path = (Path) base.FindName("path");
        //    }
        //}

        private void StockProfessionInformationItem_Loaded(object sender, RoutedEventArgs e)
        {
            int num = int.Parse((from itemset in this.doc.Elements("Configs").Elements<XElement>("NewsInfoArea").Elements<XElement>("NewsItemSetting") select itemset).ToList<XElement>()[0].Element("ItemStringCount").Value);
            if (this.itemContent.Length < num)
            {
                this.tbl.Text = this.itemContent;
            }
            else
            {
                this.tbl.Text = this.itemContent.Substring(0, num) + "..";
            }
            this.tbl.Cursor = Cursors.Hand;
        }

        private void tbl_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Application.Current.IsRunningOutOfBrowser)
            {
                this.tbl.Cursor = Cursors.Arrow;
            }
            if (!Application.Current.IsRunningOutOfBrowser)
            {
                ((TextBlock) sender).TextDecorations = TextDecorations.Underline;
            }
        }

        private void tbl_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Application.Current.IsRunningOutOfBrowser)
            {
                ((TextBlock) sender).TextDecorations = null;
            }
        }

        private void tbl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!Application.Current.IsRunningOutOfBrowser)
            {
                HtmlPage.Window.Navigate(new Uri(this.newsHref), "_blank");
            }
        }

        public string ItemContent
        {
            get
            {
                return this.itemContent;
            }
            set
            {
                this.itemContent = value;
            }
        }

        public string NewsDate { get; set; }

        public string NewsHref
        {
            get
            {
                return this.newsHref;
            }
            set
            {
                this.newsHref = value;
            }
        }

        public string NewsID { get; set; }

        public string NewsSymbol { get; set; }
    }
}
